package xyz.ljcc.ccmt.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import xyz.ljcc.ccmt.config.LoginInterceptor;

@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter{

	Logger logger = LoggerFactory.getLogger(MyMvcConfig.class);
	
	@Bean
	public WebMvcConfigurerAdapter myWebMvcConfigurerAdapter() {
		WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {
			/*
			 * 添加拦截器
			 */
			@Override
			public void addInterceptors(InterceptorRegistry registry) {
				logger.info("注册登录拦截器");
				// 添加登录认证拦截器
				registry.addInterceptor(new LoginInterceptor())
						.addPathPatterns("/**")
						.excludePathPatterns("/login.html","/doLogin","/verify/regist","/verify/check","/getpass/**");
			}

			/*
			 * 添加视图映射
			 */
			@Override
			public void addViewControllers(ViewControllerRegistry registry) {
				logger.info("************  注册视图映射  ***********");
				registry.addViewController("/").setViewName("index");
				registry.addViewController("/index").setViewName("index");
				registry.addViewController("/index.html").setViewName("index");
				registry.addViewController("/login").setViewName("login");
				registry.addViewController("/login.html").setViewName("login");
			}
			
		};
		return adapter;
	}
	
}
